package com.risk.web.controller.kefu;

import com.risk.common.annotation.Log;
import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.enums.BusinessType;
import com.risk.kernel.domain.KfDataOperate;
import com.risk.kernel.service.IKfDataOperateService;
import com.risk.kernel.vo.DataImportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2024/11/24
 * @description:
 */

@Api("客服系统数据操作管理")
@RestController
@RequestMapping("/kf/operate")
public class KeFuDataOperateController extends BaseController {
    @Autowired
    private IKfDataOperateService kfDataOperateService;

    /**
     * 查询【任务列表】列表
     */
    @PreAuthorize("@ss.hasPermi('kf:operate:list')")
    @ApiOperation("操作记录分页查询")
    @GetMapping("/page/list")
    public TableDataInfo list(String mobile) {
        startPage();
        List<KfDataOperate> list = kfDataOperateService.selectKfDataOperateList(mobile);
        return getDataTable(list);
    }


    /**
     * hive导数到mysql
     */
    @Log(title = "【hive导数到mysql】", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('kf:operate:add')")
    @PostMapping(value = "/import")
    public AjaxResult hiveDataImportToMysql(@RequestBody DataImportVo dataImportVo) {
        String name = "";
        if (StringUtils.isNotEmpty(getNickName())) {
            name = getNickName();
        } else {
            name = getUsername();
        }
        dataImportVo.setCreateBy(name);
        AjaxResult result = kfDataOperateService.hiveDataImportToMysql(dataImportVo);
        return result;
    }


    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('kf:operate:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(kfDataOperateService.deleteKfDataOperateByIds(ids));
    }
}
